package ngat.oss;

import ngat.net.*;
import ngat.net.transaction.*;
import ngat.message.base.*;
import ngat.message.OSS.*;

import java.util.*;

/** Factory for generating handlers for OSS commands.
 * <br>
 * $Id: OSSCommandImplFactory.java,v 1.1 2006/11/27 08:45:00 snf Exp $
 */
public class OSSCommandImplFactory implements RequestHandlerFactory {

  //   /** OSS Transaction Executor.*/
//     protected TransactionManager.Executor tmx;

    Vector queue;

    /** Selects the appropriate handler for the specified command. 
     * May return <i>null</i> if the ProtocolImpl is not defined or not an
     * instance of JMSMA_ProtocolServerImpl or the request is not
     * defined or not an instance of TRANSACTION. */
    public RequestHandler createHandler(ProtocolImpl serverImpl,
					Object       request) {
	
	// Deal with undefined and illegal args.
	if ( (serverImpl == null) ||
	     ! (serverImpl instanceof JMSMA_ProtocolServerImpl) ) return null;
	if ( (request == null)    || 
	     ! (request instanceof TRANSACTION) ) return null;
	
	// Cast to correct subclass.
	COMMAND command = (COMMAND) request;
	
	// Choose a generic OSS_CommandImpl.
	// All it needs to do is submit the TRANSACTION to the TMX and wait 
	// around for it to be executed.
	
	OSSCommandImpl impl = new OSSCommandImpl((JMSMA_ProtocolServerImpl)serverImpl, 
						 (TRANSACTION)request,
						 queue);
	return impl;
	
    }
    
 //    /** Create an  OSSCommandImplFactory using the supplied Executor.
//      * @param tmx The OSS Transaction Executor.
//      */
//     public OSSCommandImplFactory(TransactionManager.Executor tmx) {
// 	this.tmx = tmx;
//     }

    public OSSCommandImplFactory(Vector queue) {
	this.queue = queue;
    }

}    
